home *** CD-ROM | disk | FTP | other *** search
- /* Displays a file of slides on a VGA Screen - version 2 */
- /* Written by Nigel Salt 1991 */
- /******************************************************
- Nigel Salt
- 25 Lower Station Rd
- Crayford
- Kent
- DA1 3PY
- UK
-
- Phone +44 322 553260
-
- Email nao@cix.complink.co.uk
- ******************************************************/
-
- /* This version pre-reads the slide file to facilitate
- jumping up and down
- Also traps last slide until Esc is pressed */
-
- #include <graph.h>
- #include <stdio.h>
- #include <conio.h>
- #include <string.h>
- #include <process.h>
- #include <stdlib.h>
- #include <ctype.h>
-
- #define MAXSLIDES 1000
- #define MAXLINE 255
-
- /***************/
- /* Global Data */
- /***************/
- static FILE *f;
- static short vidmode=_VRES16COLOR;
- static int fonth=43;
- static char fonthstr[4]="43";
- static char headbase[64]="bw20t'helv'h";
- static char headfont[64]="bw20t'helv'h43";
- static int headcolor=12;
- static char bodybase[64]="bw20t'helv'h";
- static char bodyfont[64]="bw20t'helv'h43";
- static int bodycolor=10;
- static char divide[]="════════════════════════════════════════════════════════════════════════════════════════════════";
- static char buff[MAXLINE+1];
- static char slidefile[80];
- static char copyright[]="Nigel Salt (c) 1991";
- static long slidestart[MAXSLIDES];
- static int slideno=0;
- static int numslides=0;
- static long bgcolors[16]=
- {
- _BLACK,
- _BLUE,
- _GREEN,
- _CYAN,
- _RED,
- _MAGENTA,
- _BROWN,
- _WHITE,
- _GRAY,
- _LIGHTBLUE,
- _LIGHTGREEN,
- _LIGHTCYAN,
- _LIGHTRED,
- _LIGHTMAGENTA,
- _YELLOW,
- _BRIGHTWHITE
- };
-
- /***********************/
- /* Function prototypes */
- /***********************/
- void showslides(void);
- void copviol(void);
- void main(int argc,char *argv[]);
- void setopts(void);
- void userin(void);
- int getslides(void);
-
- /******************************/
- void main(int argc,char *argv[])
- /******************************/
- {
- static char progpath[65];
- char *lastslash;
-
- /* Find out program home directory */
- lastslash=strrchr((char *)argv[0],'\\');
- if (lastslash==NULL)
- progpath[0]='\0';
- else
- {
- *(lastslash+1)='\0';
- strcpy(progpath,argv[0]);
- }
-
- /* Register fonts */
- strcpy(buff,progpath);
- strcat(buff,"*.fon");
- if (! _registerfonts((char far *)buff))
- {
- fprintf(stderr,"\nNo '.fon' files found");
- exit(1);
- }
-
- /* Check copyright */
- if (copyright[0]!='N')
- copviol();
-
- /* Get slide file name if any */
- if (argc>1)
- strcpy(slidefile,argv[1]);
- else
- strcpy(slidefile,"demo.sld");
-
- /* Try to open slide file */
- f=fopen(slidefile,"r");
- if (f==NULL)
- {
- fprintf(stderr,"\nCannot find show file '%s'",slidefile);
- exit(1);
- }
-
- /* Find start of each slide */
- numslides=getslides();
- if (numslides==0)
- {
- fprintf(stderr,"\nCannot find any slides in file '%s'",slidefile);
- exit(1);
- }
-
-
- /* Set default video mode to VGA 16 color */
- vidmode=_VRES16COLOR;
- if (!_setvideomode(vidmode))
- vidmode=0;
- slidestart[0]=0L;
-
- /* Get first line of slide show file */
- fseek(f,0,SEEK_SET);
- fgets(buff,MAXLINE,f);
- showslides();
- _setvideomode(_DEFAULTMODE);
- exit(0);
- }
-
- /******************************/
- int getslides(void)
- /******************************/
- {
- long lastline;
- int slidesfound;
- long curline;
-
- slidesfound=0;
- curline=lastline=ftell(f);
- while (!feof(f)&&numslides<MAXSLIDES)
- {
- if (fgets(buff,MAXLINE,f)==NULL)
- continue;
-
- /* Skip any control lines */
- while (buff[0]=='#'&&!feof(f))
- fgets(buff,MAXLINE,f);
-
- /* Skip through the text lines */
- while (buff[0]!='#'&&!feof(f))
- {
- lastline=ftell(f);
- fgets(buff,MAXLINE,f);
- }
-
- /* Record start of first line following text of previous slide */
- if (curline!=lastline)
- {
- slidesfound++;
- slidestart[slidesfound]=lastline;
- }
- }
- return slidesfound;
- }
-
- /* On entry the show file is open and set to start of slide */
- /* Buff contains the first line to be processed */
- /******************************/
- void showslides()
- /******************************/
- {
- int i;
- int lastslide;
-
- if (strlen(copyright)!=19)
- copviol();
- while (slideno<numslides)
- {
- /* Save start position of current slide */
- setopts();
- _clearscreen(_GCLEARSCREEN);
- _setfont(headfont);
- _setcolor(headcolor);
- _moveto(0,0);
- _outgtext(divide);
- _moveto(0,fonth);
- _outgtext(divide);
- _moveto(fonth/2,7*fonth/8);
- _outgtext(buff);
-
- _setfont(bodyfont);
- _setcolor(bodycolor);
- fgets(buff,MAXLINE,f);
- for (i=0;i<8&&buff[0]!='#'&&!feof(f);i++)
- {
- _moveto(20,(i+2)*fonth);
- _outgtext(buff);
- fgets(buff,MAXLINE,f);
- }
- lastslide=slideno;
- userin();
- while (slideno==lastslide)
- userin();
- fseek(f,slidestart[slideno],SEEK_SET);
- fgets(buff,MAXLINE,f);
- }
- }
-
- /******************************/
- void copviol(void)
- /******************************/
- {
- _setvideomode(_DEFAULTMODE);
- fprintf(stderr,"\nCOPYRIGHT VIOLATION");
- exit(99);
- }
-
- /******************************/
- void setopts(void)
- /******************************/
- {
- int modechanged;
- modechanged=0;
- while (buff[0]=='#'&&!feof(f))
- {
- switch (buff[1])
- {
- case 'V':
- switch (toupper(buff[2]))
- {
- case 'V':
- if (vidmode!=_VRES16COLOR)
- {
- vidmode=_VRES16COLOR;
- if (!_setvideomode(vidmode))
- {
- _setvideomode(_DEFAULTMODE);
- fprintf(stderr,"\nVGA video mode not supported");
- fprintf(stderr,"\nTry #VE at the start of your show");
- exit(1);
- }
- else
- {
- fonth=43;
- modechanged=1;
- vidmode=_VRES16COLOR;
- strcpy(fonthstr,"43");
- }
-
- }
- break;
- case 'E':
- if (vidmode!=_ERESCOLOR)
- {
- vidmode=_ERESCOLOR;
- if (!_setvideomode(vidmode))
- {
- _setvideomode(_DEFAULTMODE);
- fprintf(stderr,"\nEGA video mode not supported");
- fprintf(stderr,"\nTry #VC at the start of your show");
- exit(1);
- }
- else
- {
- fonth=31;
- strcpy(fonthstr,"31");
- modechanged=1;
- }
- }
- break;
- case 'C':
- if (vidmode!=_HRESBW)
- {
- vidmode=_HRESBW;
- if (!_setvideomode(vidmode))
- {
- _setvideomode(_DEFAULTMODE);
- fprintf(stderr,"\nCGA video mode not supported");
- fprintf(stderr,"\nI am sorry but you cannot use PCSLIDE");
- exit(1);
- }
- else
- {
- fonth=18;
- strcpy(fonthstr,"18");
- modechanged=1;
- }
- }
- break;
- default:
- break;
- }
- break;
- case 'H':
- headcolor=atoi(&buff[2]);
- break;
- case 'B':
- bodycolor=atoi(&buff[2]);
- break;
- case 'G':
- _setbkcolor(bgcolors[atoi(&buff[2])%16]);
- break;
- default:
- break;
- }
- fgets(buff,MAXLINE,f);
- }
- /* Have now got video mode in vidmode
- color for headings in headcolor
- color for body in bodycolor */
- if (vidmode==0)
- {
- _setvideomode(_DEFAULTMODE);
- fprintf(stderr,"\nVGA video mode not supported");
- fprintf(stderr,"\nTry #VE at the start of your show");
- exit(1);
- }
- if (modechanged)
- {
- strcpy(headfont,headbase);
- strcat(headfont,fonthstr);
- strcpy(bodyfont,bodybase);
- strcat(bodyfont,fonthstr);
- }
- }
-
- /* Resets slideno to number of next slide */
- /******************************/
- void userin(void)
- /******************************/
- {
- unsigned int keypress;
-
- /* Wait for a key press */
- while (!kbhit());
-
- /* Get key press */
- keypress=getch();
-
- /* Process extended scan codes */
- if (keypress==0)
- keypress=256*getch();
-
- /* Process escape key */
- if (keypress==27)
- {
- _setvideomode(_DEFAULTMODE);
- exit(0);
- }
-
- switch (keypress)
- {
- /* Up or left - back one slide */
- case 72*256:
- case 75*256:
- slideno-=1;
- break;
-
- /* Home - goto slide 1 */
- case 71*256:
- slideno=0;
- break;
-
- /* End - goto last slide */
- case 79*256:
- slideno=numslides-1;
- break;
-
- /* PgUp - go back 5 slides */
- case 73*256:
- slideno-=5;
- break;
-
- /* PgDn - go forward 5 slides */
- case 81*256:
- slideno+=5;
- break;
-
- /* Any other key goes to next slide */
- default:
- slideno++;
- break;
- }
- if (slideno>=numslides) slideno=numslides-1;
- if (slideno<0) slideno=0;
- }
-
-